package org.examples;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.synchronoss.cloud.nio.stream.storage.StreamStorage;

import java.io.*;

public class MemOnlyStorage extends StreamStorage {

  private static final Logger log = LoggerFactory.getLogger(org.examples.MemOnlyStorage.class);

  @Override
  public int getBytesCount() {
    return totoalBytes;
  }

 int totoalBytes;




  // ------------
  // CONSTRUCTORS
  // ------------



  protected MemOnlyStorage( ) {

  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void write(int b) throws IOException {
 totoalBytes+=1;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void write(byte[] b, int off, int len) throws IOException {
    totoalBytes+=len;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void write(byte[] b) throws IOException {
    totoalBytes+=b.length;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void flush() throws IOException {
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void close() throws IOException {
  }




  /**
   * <p> Dismisses the {@code DeferredMemOnlyStorage} closing quietly the {@code OutputStream} and deleting the underlying file if it
   * exists. This method is useful just in case of errors to free the resources and once called the {@code DeferredMemOnlyStorage} is
   * not usable anymore.
   *
   * @return <code>true</code> if and only if the file was created and it has been deleted successfully; <code>false</code> otherwise.
   */
  @Override
  public boolean dispose() {

    return true;
  }



}
